/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Compressor.java
 *
 * Created on 25 oct. 2009, 18:00:42
 */

package huffman;

import java.io.File;
import javax.swing.JFileChooser;

/**
 *
 * @author ksz
 */
public class Compressor extends javax.swing.JFrame {

    /** Creates new form Compressor */
    public Compressor() {
        initComponents();
        this.setLocationRelativeTo(this.getParent());
        setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        fichier = new javax.swing.JMenu();
        compresser = new javax.swing.JMenuItem();
        decompresser = new javax.swing.JMenuItem();
        apropos = new javax.swing.JMenuItem();
        quitter = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/the-compressor.jpg"))); // NOI18N

        fichier.setText("Fichier");

        compresser.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/plus_icon.gif"))); // NOI18N
        compresser.setText("Compresser");
        compresser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                compresserActionPerformed(evt);
            }
        });
        fichier.add(compresser);

        decompresser.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/minus_icon.png"))); // NOI18N
        decompresser.setText("Decompresser");
        decompresser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                decompresserActionPerformed(evt);
            }
        });
        fichier.add(decompresser);

        apropos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/apropos.png"))); // NOI18N
        apropos.setText("About");
        apropos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aproposActionPerformed(evt);
            }
        });
        fichier.add(apropos);

        quitter.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/quitter.png"))); // NOI18N
        quitter.setText("Quitter");
        quitter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quitterActionPerformed(evt);
            }
        });
        fichier.add(quitter);

        jMenuBar1.add(fichier);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabel1)
                .addContainerGap(27, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void aproposActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aproposActionPerformed
        APropos about = new APropos(this, false);
    }//GEN-LAST:event_aproposActionPerformed

    private void quitterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitterActionPerformed
        System.exit(0);
    }//GEN-LAST:event_quitterActionPerformed

    private void compresserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_compresserActionPerformed
        JFileChooser fc = new JFileChooser();
        int returnVal = fc.showDialog(fc, "Choisissez le fichier à compresser");

        if(returnVal == JFileChooser.APPROVE_OPTION) {

            File fichier = fc.getSelectedFile();

            Encodeur encodeur = new Encodeur(fichier.getAbsolutePath());
            Thread th = new Thread (encodeur);
            th.start();

        }

    }//GEN-LAST:event_compresserActionPerformed

    private void decompresserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_decompresserActionPerformed
        JFileChooser fc = new JFileChooser();
        int returnVal = fc.showDialog(fc, "Choisissez le fichier à décompresser");

        if(returnVal == JFileChooser.APPROVE_OPTION) {

            File fichier = fc.getSelectedFile();

            Decodeur encodeur = new Decodeur(fichier.getAbsolutePath());
            Thread th = new Thread (encodeur);
            th.start();

        }
    }//GEN-LAST:event_decompresserActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Compressor().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem apropos;
    private javax.swing.JMenuItem compresser;
    private javax.swing.JMenuItem decompresser;
    private javax.swing.JMenu fichier;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem quitter;
    // End of variables declaration//GEN-END:variables

}
